import React, { useEffect, useState } from "react";
import { View, Text, StyleSheet, Dimensions } from "react-native";
import NetInfo from "@react-native-community/netinfo";
import { enableScreens } from "react-native-screens";
import Nav from "./router";

import {observer} from 'mobx-react';
// import {App as app} from './data';

import { ApolloProvider } from '@apollo/react-hooks';

enableScreens();

interface Props { }

const App: (props: Props) => JSX.Element = props => {
    /**
     *  网络状况
     */
    var connected: boolean = true;
    /**
     *  无网状态 : none unknow
     */
    function checkNetwork(state:any) {
            let type: boolean = true;
            let reachable: boolean = true;
            if (state.type == "none" || state.type == "unknow") type = false;
            if (!reachable) reachable = false;
            if (reachable) {
                if (type) {
                    connected = true;
                } else {
                    connected = false;
                }
            } else {
                connected = false;
            }
            //TODO: 更新appstore 的connected值
            // app.setConnected(connected);
    }

    useEffect(() => {
        NetInfo.fetch().then(state => { checkNetwork(state) });
        const listener = NetInfo.addEventListener( state => {
            checkNetwork(state)
        });
        return () => listener()
     },[]);

    return <Nav/>
};

export default observer(App);
